(function($){
	$.extend($.fn, {
		initGrid : function(options) {
			var $this = $(this[0]);
			var id=$this.attr("id");
			$this.after("<div id=\"" + id+"_-_Pager" +"\"></div>");
			if(!options.colNames || options.colNames.length <= 0){
				var tempColNames = [];
				$.each( options.colModel , function ( i , e ){
					var temp;
					if(this.colNames){
						temp = this.colNames;
					}else{
						temp = this.name;
					}
					tempColNames.push(temp);
				})
				options.colNames = tempColNames
			}
		
			
			$this.jqGrid($.extend({
							jsonReader : {repeatitems: false},
							pager : "#"+id+"_-_Pager",
							mtype : "post",
							datatype : "json",
							autowidth : true,
							viewrecords : true,
							multiselect : true,
							rowNum : 15,
							rowList : [10, 15, 30],
							rownumbers : true	//显示序号
						}, options)).navGrid("#"+id+"_-_Pager",{add:false,del:false,edit:false,search:false});
		},
		searchGrid : function(params){
			objParams = params;
	        //获得当前postData选项的值   
	        var postData = $(this[0]).jqGrid("getGridParam", "postData");
	        //将查询参数融入postData选项对象   
	        $.extend(postData, params);
	        $(this[0]).jqGrid("setGridParam", {
	            search: true
	        }).trigger("reloadGrid", [{
	            page: 1
	        }]); // 重新载入Grid表格
		},
		getSelectedIds : function(){
			var gridIds = $(this[0]).jqGrid("getGridParam","selarrrow");
			return gridIds;
		},
		ifGridSelected : function(){
			var ids = this.getSelectedIds();
			return ids.length > 0;
		},
		ifGridSelectedOne : function(){
			var ids = this.getSelectedIds();
			return ids.length === 1;
		},
		reloadGrid : function(){
			$(this[0]).trigger("reloadGrid", [{
				page: 1
			}])
		},
		getSelectedRows : function(){
			var ids = this.getSelectedIds();
			var rowDataArr = [];
			var grid = $("#"+$($(this[0])).context.id);
			$.each(ids,function( i , e ){
				var rowData = grid.jqGrid('getRowData', e);
				rowDataArr.push(rowData);
			});
			return rowDataArr;
		}
	});
})(jQuery);